package com.archetypus.projectschedule.web.common.cfg;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.archetypus.projectschedule.common.Configuration;

public class InitProjectScheduler extends HttpServlet {

	private static final long serialVersionUID = 2982081308707656210L;

	public void init() throws ServletException {
		super.init();
		try {
			Enumeration<?> claves = getServletConfig().getInitParameterNames();
			Map<String, String> appParameters = new HashMap<String, String>();
			String key = null;
			while (claves.hasMoreElements()) {
				key = (String) claves.nextElement();
				appParameters
						.put(key, getServletConfig().getInitParameter(key));
			}
			
			appParameters.put("realPath", getServletContext().getRealPath("/").replace('\\', '/'));
			
			Configuration.getInstance().init(appParameters);
		} catch (Exception e) {
			throw new ServletException(e);
		}
	}
}
